
<script setup>
// import { ref } from 'vue';
// import axios from 'axios';
//
// const title = ref('');
// const content = ref('');
// const author = ref('');
// const date = ref('');
//
// const getText = async () => {
//   try {
//     const result = await axios({
//       url: "http://1.116.198.235/article/api/zxnews.php?type=info&aid=" + localStorage.getItem("aid"),
//       method: "get",
//       headers: {
//         'Content-Type': 'application/json',
//         'Authorization': localStorage.getItem('userLoginToken'),
//       }
//     });
//
//     if (result.data.code === "ok") {
//       title.value = result.data.result.title;
//       content.value = result.data.result.content;
//       author.value = result.data.result.user;
//       date.value = result.data.result.date;
//       // 其他数据更新
//     } else {
//       console.error(result.data.msg);
//     }
//   } catch (error) {
//     console.error("An error occurred while fetching data:", error);
//   }
// };
// getText();

import { ref } from 'vue';
import { useRoute } from "vue-router";
import { ElMessage } from "element-plus";
import axios from 'axios';
document.title = "查看资讯";
let $route = useRoute();
let InfoData = ref({});

const getInfo = () => {
  axios({
    url: `http://1.116.198.235/article/api/zxnews.php?type=info&aid=`+ $route.query.aid,
    headers: {
      'Content-Type': 'application/json',
      'Authorization': localStorage.getItem('userLoginToken'),
    },
  }).then((result) => {
    console.log(result)
    if (result.data.code === "ok") {
      InfoData.value.title = result.data.result.title;
      InfoData.value.content = result.data.result.content;
      InfoData.value.author = result.data.result.user;
      InfoData.value.date = result.data.result.date;
    } else {
      ElMessage.error(result.data.msg);
    }
  });
};
getInfo($route.query.id);
</script>

<template>
  <div id="bast-box">
    <h3 id="title">{{InfoData.title}}</h3>
    <hr>
    <div id="author">
      <span>编辑：<i id="exit">{{InfoData.author}}</i></span>
      <span>日期：<i id="date">{{InfoData.date}}</i></span>
    </div>
    <div id="content">{{InfoData.content}}</div>
  </div>
</template>



<style scoped>
#bast-box, p, a {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: inherit;
  width: 100%;
  height: 100vh;
  background: linear-gradient(to bottom,#a9e3a1 ,rgb(255, 255, 255));
  text-decoration: none;
}

h3 {
  line-height: 50px;
  text-align: center;
  color: #9fe384;
  font-size: 26px;
  letter-spacing: 7px;
  text-shadow: 0 -1px 20px white;
  font-family: "华文琥珀";
}

hr {
  width: 80%;
  margin: 30px auto 15px;
  border: 1px solid #666;
}

#content {
  width: 65%;
  font-size: 17px;
  margin: 30px auto 0;
  padding-bottom: 60px;
}

#author {
  width: 65%;
  text-align: center;
  margin: 0 auto;
}

#author > span {
  margin-right: 20px;
}

#author > span > i {
  font-style: normal !important;
}
</style>